home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / utility / bat_faq1.zip / BAT-FAQ.ASC
Text File  |  1996-07-03  |  32KB  |  680 lines

  1.  
  2.                           THE BATPOWER FAQ,
  3.                     or Frequently Asked Questions
  4.  
  5. |     ***              Last revision: 28 Jun 96              ***
  6.  
  7.    +----------------------------------------------------------------+
  8.    |     Table of Contents for     | 14. Path over 128 characters   |
  9.    |  FREQUENTLY ASKED QUESTIONS,  | 15. What is the 'MUF'?         |
  10.    |  (FAQ) for the BATPOWER Echo  | 16. Recursion/Loops in a BAT   |
  11.    |-------------------------------+ 17. Start-up screen rotation   |
  12.    |  1. How to reboot in a BATch  | 18. Tidying output from a BAT  |
  13.    |  2. Communicate with a modem  | 19. Using ANSI codes in a BAT  |
  14.    |  3. Date & Time Use in a BAT  | 20. REM or :: in a BATch       |
  15.    |  4. Combine files into one    | 21. Is bat run from Windows ?  |
  16.    |  5. Formatting Disks Q&A      | 22. Using Ctrl+Z in a BATch    |
  17.    |  6. Getting errorlevel Q&A    | 23. Zero byte files- questions |
  18.    |  7. Help with making a menu   | 24. Banish 'Retry,Abort,Ignore'|
  19.    |  8. Is TSR loaded in memory ? | 25. Getting user BATch input   |
  20.    |  9. Jump back to prior dir    | 26. BATch Programming Books    |
  21.    | 10. Find&Replace text in file | 27. BFDS FDN questions         |
  22.    | 11. Low level HD format Q&A   | 28. Scripts posted in BATPOWER |
  23.    ||12. FOR..IN..DO Q&A's         | 29.                            |
  24.    | 13. Out of Environment Q&A's  | 30.                            |
  25.    +----------------------------------------------------------------+
  26.  
  27.  
  28.  1.                 HOW TO REBOOT IN A BATch
  29.                     ~~~~~~~~~~~~~~~~~~~~~~~~
  30.   Q: How do I reboot the PC from inside a batch file ?
  31.   A: ECHO G=FFFF:0 | DEBUG >NUL   for MSDOS} these occasionally
  32.      ECHO GFFFF:0000 | SID >NUL   for DRDOS} will give garbage
  33.   --------------------------------------------------------------
  34.      ECHO HPS╦>REBOOT.COM    This seems reliable, most editors
  35.      REBOOT.COM              will allow Alt+203 to get the ╦
  36.                              Hold the ALT key while 2 0 3 is
  37.                          entered at the r/h keypad (Numlock ON)
  38.  --------------------------------------------------------------
  39.      This DEBUG script will produce COLDBOOT.COM when you run it
  40.   ------------------------------------+ thus:  DEBUG<SCRIPT.EXT
  41.      If your using  BNU type: BNU /B  |
  42.      If your using  XDO type: XU BOOT | N COLDBOOT.COM
  43.      If your using 4DOS type: REBOOT  | E 0100 48 50 53 CB 0D 0A
  44.   ------------------------------------+ RCX
  45.   Flush your Disk Cache before you use| 0006
  46.    !!!!   any of these methods   !!!! | W
  47.   for Smartdrive this is: SMARTDRV /C | Q
  48.  
  49.  
  50.  2.                 COMMUNICATE WITH A MODEM
  51.                     ~~~~~~~~~~~~~~~~~~~~~~~~
  52.  Q: How do I communicate with my modem either in a BATch or on
  53.     the command-line ?
  54.  A: After setting up the COM port with MODE if required simply
  55.     use DOS redirection > to ECHO AT commands to it.
  56.     E.G. MODE COM1 baud=19200 data=8 parity=n stop=1
  57.          ECHO AT&FF10\N4&D3E0M0Q1S0=1&W0>COM1
  58.     might be used to set up a modem loading a profile into it
  59.     or if you wanted to leave a computer accessible from a
  60.     remote location you might shell out of a communications
  61.     program and run a batch file containing:
  62.          %COMSPEC% /e:1024 >COM1 <COM1
  63.     which would start a copy of the command processor to accept
  64.     input from the remote computer and output to it.
  65.     (with MS-DOS error messages would not get sent but 4DOS
  66.         allows STNDERR device writes to be re-directed)
  67.  
  68.  
  69.  3.                 DATE & TIME USE IN A BAT
  70.                     ~~~~~~~~~~~~~~~~~~~~~~~~
  71.   Q: How do I create a LogFile or get the current Time & Date
  72.      into environment variables.
  73.   A: A number of utilities to get the time or date into an
  74.      envar exist, among them are P2E, GET25, BATCHMAN & STRINGS
  75.      but a pure MS-DOS solution exists too:
  76.       VER|TIME|FIND "Current">$$TEMP$$.BAT
  77.       ECHO SET CTIME=%%3>CURRENT.BAT
  78.       $$TEMP$$.BAT
  79.      will place the current TIME into an envar called CTIME and
  80.      TIME can be replaced with DATE above to create CDATE.
  81.      To create a log of system boots the following could be
  82.      inserted into the AUTOEXEC.BAT file:
  83.       ECHO -=-=-=-=-=-=-=-=-=-=-=-=-=-=->>BOOTLOG.TXT
  84.       ECHO System booted !!! >>BOOTLOG.TXT      : For more   :
  85.       VER|TIME|FIND "Current">>BOOTLOG.TXT      : techniques :
  86.       VER|DATE|FIND "Current">>BOOTLOG.TXT      : type  $    :
  87.  
  88.     Using P2E to create filenames in YYMMDD.* format :
  89.  @ECHO OFF
  90.  ECHO.|DATE|P2E /E MM /L 1 /M 21,2 /E DD /L 1 /M 24,2 /E YY /L 1 /M 29,2
  91.  ECHO This is a New File>%YY%%MM%%DD%.TXT
  92.  
  93.     Using PROMPT and CALL to create an 'ECHO'able Current Date & Time :
  94.  @ECHO OFF
  95.  ECHO @PROMPT LOG ON: $d at $t$h$h$h>C:\TEMP\TEMP$$$$.BAT
  96.  %COMSPEC% /C C:\TEMP\TEMP$$$$|FIND ":">>C:\LOGONS.TXT
  97.     Typical resultant contents of c:\logons.txt will be:
  98.  LOG ON: Fri 12-27-1993 at 09:37:48
  99.  LOG ON: Tue 01-04-1994 at 08:54:26
  100.           --etc.--etc.--
  101.     The section of the line between @PROMPT and the > is customizable
  102.     and all $codes valid for the PROMPT command can be used as well as
  103.     the current system date and time.
  104.  
  105.  
  106.  4.                  COMBINE FILES INTO ONE
  107.                      ~~~~~~~~~~~~~~~~~~~~~~
  108.   Q: I have lots of text files that I want to combine into one,
  109.      how can I automate this with a BATch.
  110.   A: The DOS COPY command can be used or redirection of TYPE's
  111.      output as follows:
  112.          COPY *.TXT ALL.XXX
  113.          RENAME ALL.XXX ALL.TXT
  114.      or
  115.          FOR %%f IN (*.TXT) DO TYPE %%f>>ALL.XXX
  116.          RENAME ALL.XXX ALL.TXT
  117.      The renaming of the resultant file is necessary, as when
  118.      it is created by the first COPY or TYPE operation, were
  119.      it called ALL.TXT it would immediately qualify for
  120.      inclusion in the command as it would match the filespec.
  121.      COPY can do binary concatenations too, with the /B param
  122.      MS-Windows remakes WIN.COM everytime Setup is used similar
  123.      to:  COPY /B WIN.CNF+VGALOGO.LGO+VGALOGO.RLE WIN.COM
  124.  
  125.  
  126.  5.                  FORMATTING DISKS- Q & A
  127.                      ~~~~~~~~~~~~~~~~~~~~~~~
  128.   Q: How do I format a disk without DOS asking me questions ?
  129.   A: With MS-DOS 3.3 use     FORMAT A: /H
  130.      With MS-DOS 4.0+ use    FORMAT A: /AUTOTEST
  131.  
  132.      !!!  BEWARE - THIS WORKS ON HARD DISKS TOO !!!
  133.  
  134.      There are a number of other undocumented switches for both
  135.      FORMAT and other MS-DOS features detailed in the MUF.
  136.       (For information about the MUF see item # 15. below)
  137.  
  138.  
  139.  6.                 GETTING ERRORLEVELS- Q & A
  140.                     ~~~~~~~~~~~~~~~~~~~~~~~~~~
  141.   Q: How do I echo the errorlevel returned by a program to the
  142.      screen so I can 'debug' my batch files ?
  143.   A: There are a couple of utilities that can do this but the
  144.      method used for the FAQ is the pure DOS solution below :
  145.  
  146.   FOR %%E IN (0,1,2) DO IF ERRORLEVEL %%E00 SET ERLVL=%%E
  147.   IF "%ERLVL%"=="0" SET ERLVL=
  148.   SET RANGE=0,1,2,3,4,5,6,7,8,9
  149.   IF "%ERLVL%"=="2" SET RANGE=0,1,2,3,4,5
  150.   FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E0 SET ERLVL=%ERLVL%%%E
  151.   IF "%ERLVL%"=="0" SET ERLVL=
  152.   IF NOT "%ERLVL%"=="25" SET RANGE=0,1,2,3,4,5,6,7,8,9
  153.   FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E SET ERLVL=%ERLVL%%%E
  154.   SET RANGE=
  155.   ECHO Errorlevel is %ERLVL%
  156.  
  157.     Here is a line-by-line walk thru' of this courtesy Rudy Lachin:
  158.  
  159.   FOR %%E IN (0,1,2) DO IF ERRORLEVEL %%E00 SET ERLVL=%%E  If errorlevel
  160.         is greater than 0 set ERLVL to 0, if >100 to 1 and if >200 to 2.
  161.   IF "%ERLVL%"=="0" SET ERLVL=   If ERLVL=0 clear it (suppress leading 0)
  162.   SET RANGE=0,1,2,3,4,5,6,7,8,9    Now we've set the hundreds check tens
  163.   except when the errorlevel is >200 in which case we only want to go up
  164.   IF "%ERLVL%"=="2" SET RANGE=0,1,2,3,4,5                to the fifties.
  165.   FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E0 SET ERLVL=%ERLVL%%%E
  166.   If the errorlevel in this range of tens is above x00 set ERLVL to x00,
  167.               if > x10 set ERLVL to x10, if > x20 set ERLVL to x20, etc.
  168.   IF "%ERLVL%"=="0" SET ERLVL=   If ERLVL=0 clear it (suppress